package com.fm.base.database;

import com.fm.base.logic.Operator;

import java.util.Arrays;
import java.util.Collection;

public class DBDataFilter {
	public static DBDataFilter equal(String subject, Object object) {
		return new DBDataFilter(Operator.equal, subject, object);
	}

	public static DBDataFilter and(DBDataFilter... filters) {
		return new DBDataFilter(Operator.and, filters);
	}

	public static DBDataFilter in(String subject, Object... values) {
		Object[] vals = new Object[2];
		vals[0] = subject;
		vals[1] = Arrays.asList(values);
		return new DBDataFilter(Operator.in, vals);
	}

	public static DBDataFilter in(String subject, Collection<?> values) {
		Object[] vals = new Object[2];
		vals[0] = subject;
		vals[1] = values;
		return new DBDataFilter(Operator.in, vals);
	}

	private Operator operator;
	private Object[] values;

	private DBDataFilter(Operator operator, Object... values) {
		switch (operator) {
			case equal:
				break;
			case and:
				break;
			case in:
				if (values[0] instanceof DBDataFilter) {
					throw new IllegalArgumentException("first value mustn't be " + getClass());
				}
				break;
			default:
				throw new RuntimeException("not support");
		}
		this.operator = operator;
		this.values = values;
	}

	public Operator getOperator() {
		return operator;
	}

	public Object[] getValues() {
		return values;
	}
}